#include "TinyLog.h"
#include <iostream>
#include <ctime>
#include <iomanip>

//#pragma warning (disable : 4996)		// Uncomment if last resort
//#define _CRT_SECURE_NO_DEPRECATE		// Use until last resort

int main( int argv, char** argc )
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(-1);

	SetConsoleTitle( TEXT("TinyLOG") );
	TinyLog		log;

	log.Initialize();
	bool error = log.OpenFile( "test.txt", "Test", ios_base::out );

	for( int i = 0; i<10000; i++)
		for( int j = 0; j<1000; j++)
				log.WriteFile( "TinyLog::main", "Testing", ExitCode::end_of_file );


	time_t result = time(NULL);
    //cout << asctime(localtime(&result)) << endl;

	char header[26];
	tm tm;
	localtime_s( &tm, &result );


	errno_t errNum;
	time_t timer = time(0);
	localtime_s( &tm, &timer );   // Convert time to struct tm form.
	errNum = asctime_s(header, 26, &tm);

    //cout.imbue(locale("ja_JP.utf8"));
    //cout << "ja_JP: " << put_time(&tm, "%c %z") << '\n';
	//cout << "Hello" << endl;

	// exit the program after deallocating the memory
	log.CloseFile();
	log.Uninitialize();

	system( "pause" );
	return 0;
}


//{
//	char path[MAX_PATH];
//	LPWSTR wszPath = NULL;
//	size_t pathlen;
//
//	HRESULT hr = SHGetKnownFolderPath( FOLDERID_LocalAppData, 0, 0, &wszPath); 
//	wcstombs_s(&pathlen , path, wszPath, MAX_PATH);
//
//	string pathtowrite = path;
//
//	pathtowrite += "\\DarkCrusade\\";
//	CreateDirectoryA(pathtowrite.c_str(),0);
//
//	pathtowrite += file;
//	return pathtowrite;
//}

#if defined(BOOST_POSIX_API)
{
	//  POSIX uses a 0 return to indicate success
	#   define BOOST_ERRNO    errno 
	#   define BOOST_SET_CURRENT_DIRECTORY(P)(::chdir(P)== 0)
	#   define BOOST_CREATE_DIRECTORY(P)(::mkdir(P, S_IRWXU|S_IRWXG|S_IRWXO)== 0)
	#   define BOOST_CREATE_HARD_LINK(F,T)(::link(T, F)== 0)
	#   define BOOST_CREATE_SYMBOLIC_LINK(F,T,Flag)(::symlink(T, F)== 0)
	#   define BOOST_REMOVE_DIRECTORY(P)(::rmdir(P)== 0)
	#   define BOOST_DELETE_FILE(P)(::unlink(P)== 0)
	#   define BOOST_COPY_DIRECTORY(F,T)(!(::stat(from.c_str(), &from_stat)!= 0\
	         || ::mkdir(to.c_str(),from_stat.st_mode)!= 0))
	#   define BOOST_COPY_FILE(F,T,FailIfExistsBool)copy_file_api(F, T, FailIfExistsBool)
	#   define BOOST_MOVE_FILE(OLD,NEW)(::rename(OLD, NEW)== 0)
	#   define BOOST_RESIZE_FILE(P,SZ)(::truncate(P, SZ)== 0)
	#   define BOOST_ERROR_NOT_SUPPORTED ENOSYS
	#   define BOOST_ERROR_ALREADY_EXISTS EEXIST
}
#elif defined( _WIN32 ) || defined( _WIN64 )
	//  Windows uses a non-0 return to indicate success
	#   define BOOST_ERRNO    ::GetLastError()
	#   define BOOST_SET_CURRENT_DIRECTORY(P)(::SetCurrentDirectoryW(P)!= 0)
	#   define BOOST_CREATE_DIRECTORY(P)(::CreateDirectoryW(P, 0)!= 0)
	#   define BOOST_CREATE_HARD_LINK(F,T)(create_hard_link_api(F, T, 0)!= 0)
	#   define BOOST_CREATE_SYMBOLIC_LINK(F,T,Flag)(create_symbolic_link_api(F, T, Flag)!= 0)
	#   define BOOST_REMOVE_DIRECTORY(P)(::RemoveDirectoryW(P)!= 0)
	#   define BOOST_DELETE_FILE(P)(::DeleteFileW(P)!= 0)
	#   define BOOST_COPY_DIRECTORY(F,T)(::CreateDirectoryExW(F, T, 0)!= 0)
	#   define BOOST_COPY_FILE(F,T,FailIfExistsBool)(::CopyFileW(F, T, FailIfExistsBool)!= 0)
	#   define BOOST_MOVE_FILE(OLD,NEW)(::MoveFileExW(OLD, NEW, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)!= 0)
	#   define BOOST_RESIZE_FILE(P,SZ)(resize_file_api(P, SZ)!= 0)
	#   define BOOST_ERROR_ALREADY_EXISTS ERROR_ALREADY_EXISTS
	#   define BOOST_ERROR_NOT_SUPPORTED ERROR_NOT_SUPPORTED
#endif